package com.ruoyi.enterprise.service.impl;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.enterprise.mapper.EProfessionMapper;
import com.ruoyi.enterprise.domain.EProfession;
import com.ruoyi.enterprise.service.IEProfessionService;

/**
 * 职位信息Service业务层处理
 *
 * @author JYW
 * @date 2024-02-28
 */
@Service
public class EProfessionServiceImpl implements IEProfessionService
{
    @Autowired
    private EProfessionMapper eProfessionMapper;

    /**
     * 查询职位信息
     *
     * @param id 职位信息主键
     * @return 职位信息
     */
    @Override
    public EProfession selectEProfessionById(Long id)
    {
        return eProfessionMapper.selectEProfessionById(id);
    }

    /**
     * 查询职位信息列表
     *
     * @param eProfession 职位信息
     * @return 职位信息
     */
    @Override
    public List<EProfession> selectEProfessionList(EProfession eProfession)
    {
        return eProfessionMapper.selectEProfessionList(eProfession);
    }

    /**
     * 新增职位信息
     *
     * @param eProfession 职位信息
     * @return 结果
     */
    @Override
    public int insertEProfession(EProfession eProfession)
    {
        eProfession.setCreateTime(DateUtils.getNowDate());
        return eProfessionMapper.insertEProfession(eProfession);
    }

    /**
     * 修改职位信息
     *
     * @param eProfession 职位信息
     * @return 结果
     */
    @Override
    public int updateEProfession(EProfession eProfession)
    {
        eProfession.setUpdateTime(DateUtils.getNowDate());
        return eProfessionMapper.updateEProfession(eProfession);
    }

    /**
     * 批量删除职位信息
     *
     * @param ids 需要删除的职位信息主键
     * @return 结果
     */
    @Override
    public int deleteEProfessionByIds(Long[] ids)
    {
        return eProfessionMapper.deleteEProfessionByIds(ids);
    }

    /**
     * 删除职位信息信息
     *
     * @param id 职位信息主键
     * @return 结果
     */
    @Override
    public int deleteEProfessionById(Long id)
    {
        return eProfessionMapper.deleteEProfessionById(id);
    }

    @Override
    public Map<String,BigDecimal> selectRespectWage(EProfession profession) {
        Map<String,BigDecimal> map = new HashMap<>();
        BigDecimal fund = profession.getPensionFund().multiply(profession.getPensionRate())
                .add(profession.getMedicalFund().multiply(profession.getMedicalRate()))
                .add(profession.getUnemployeedFund().multiply(profession.getUnemployeedRate()))
                .add(profession.getGongjiFund().multiply(profession.getGongjiRate()));

        BigDecimal addtion = profession.getFoodAdd()
                .add(profession.getHouseAdd())
                .add(profession.getTrafficAdd());

        map.put("fund",fund);
        map.put("addtion",addtion);
        map.put("salary",profession.getSalary());
        map.put("wageSum",profession.getSalary().add(addtion).subtract(fund));

        return map;
    }
}
